const path = require("path");

const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  mode: "development",
  context: __dirname,
  entry: {
    app: "./examples/index.js",
  },
  output: {
    filename: "[name].js",
    path: path.resolve(__dirname, "dist"),
  },
  devtool: "eval-cheap-module-source-map",
  resolve: {
    mainFields: ["module", "main"],
    extensions: [".ts", ".tsx", ".js"],
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.(png|gif|jpg|jpeg|svg|xml|json)$/,
        use: ["url-loader"],
      },
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "examples/index.html",
    }),
    // Copy Cesium Assets, Widgets, and Workers to a static directory
    // new CopyWebpackPlugin({
    //     patterns: [
    //         { from: 'node_modules/cesium/Build/Cesium/Workers', to: 'Workers' },
    //         { from: 'node_modules/cesium/Build/Cesium/ThirdParty', to: 'ThirdParty' },
    //         { from: 'node_modules/cesium/Build/Cesium/Assets', to: 'Assets' },
    //         { from: 'node_modules/cesium/Build/Cesium/Widgets', to: 'Widgets' },
    //         { from: 'data', to: 'data' }
    //     ]
    // }),
    // new webpack.DefinePlugin({
    //     // Define relative base path in cesium for loading assets
    //     CESIUM_BASE_URL: JSON.stringify('')
    // })
  ],

  // development server options
  devServer: {
    contentBase: path.join(__dirname, "dist"),
  },
};
